<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>

    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">
</head>
<body>
<div class="nav">
    五子棋
</div>
<div class="login-container">
    <div class="login-dialog">
        <!-- 标题 -->
        <h3>注册</h3>
        <!-- 输⼊⽤户名 -->
        <div class="row">
            <span>⽤户名</span>
            <input type="text" id="username" name="username">
        </div>
        <!-- 输⼊密码 -->
        <div class="row">
            <span>密码</span>
            <input type="password" id="password" name="password">
        </div>
        <!-- 提交按钮 -->
        <div class="row submit-row">
            <button id="submit">提交</button>
        </div>
    </div>
</div>
<script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js">
</script>
<script>
 // 通过 ajax 的⽅式实现登录过程
 let submitButton = document.querySelector('#submit');
 submitButton.onclick = function() {
 // 1. 先获取到用户名和密码
 let username = document.querySelector('#username').value;
 let password = document.querySelector('#password').value;
 $.ajax({
 method: 'post',
 url: '/register',
 data: {
 username: username,
 password: password
 },
 success: function(data) {
 console.log(JSON.stringify(data));
 if (data && data.username) {
 // 注册成功, 跳转到游戏⼤厅
 alert('注册成功!')
 location.assign('/login.html');
 } else {
 alert("注册失败!");
 }
 }
 });
 }
</script>


</body>
</html>